﻿@using OBUCare.Web.Infrastructure
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@{
    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();
}
@using (Html.BeginForm("ObuChangeSearch", "Report", FormMethod.Post, new { ID = "searchForm" }))
{
    <table width="100%">
        <tr>
            <td style="width: 10%; text-align: right">查询日期起：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DatePicker().Name("sDate").HtmlAttributes(new { @style = "width:170px;" }).OpenOnFocus(true).ShowButton(false)
            </td>
            <td style="width: 10%; text-align: right">查询日期止：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DatePicker().Name("eDate").HtmlAttributes(new { @style = "width:170px;" }).OpenOnFocus(true).ShowButton(false)
            </td>
            <td style="width: 10%; text-align: right">厂商：
            </td>
            <td style="width: 30%; text-align: left">
                @Html.Telerik().DropDownList().Name("Supplier").HtmlAttributes(new { @style = "width:160px;" }).BindTo(ddlHelper.GetSuppliers(UIConstants.AllItems, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
            </td>
            <td style="text-align: left">
            </td>
            <td colspan="2" style="text-align: center">
                
            </td>
            <td colspan="2" style="text-align: center">
                <input type="button" value="查询" id="btnSearch" onclick="search()" />
                @Html.Hidden("dateSql", "", new { @id = "dateSql" })
                @Html.Hidden("otherSql", "", new { @id = "otherSql" })
                <input type="submit" value="导出" id="btnReport" onclick="report()" />
                @Html.Hidden("flag", "", new { @id = "flag" })
            </td>
        </tr>
    </table>      
}
<script type="text/javascript">
    function report() {
        $('#flag').val('report');
    };
    function search() {
        $('#flag').val('');
        var form = $("#searchForm");
        dataString = form.serialize();
        $.ajax({
            type: "POST",
            url: form.attr('action'),
            data: dataString,
            cache: false,
            dataType: "json",
            success: function (data) {

                if (data.Success) {
                    //alert('成功');
                    //debugger;
                    var grid = $('#Grid').data('tGrid');
                    $('#dateSql').val(data.DateSql);
                    $('#otherSql').val(data.OtherSql);
                    grid.rebind();
                }
                else {
                    alert('失败：' + data.ErrorMsg)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                    var err = XMLHttpRequest + "<br />" + textStatus + "<br />" + errorThrown;
                    alert(err);
            }
        });
    }

</script>
@{
    ddlHelper.Dispose();    
}
